package com.example.ywj.toutiao.utils;

//import android.support.annotation.Nullable;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.ywj.toutiao.fragments.Fragment3;

import java.util.List;

//import android.support.v4.app.FragmentStatePagerAdapter;
//import java.util.ArrayList;
//搜索结果页面的fragment适配器
public class MyFragmentPageAdapter5 extends FragmentPagerAdapter {
    private static final String TAG = "MyFragmentPageAdapter2";
    private List<String> list_Title;
    private Fragment[] f;
    public MyFragmentPageAdapter5(FragmentManager fm, List<String> list_Title){
        super(fm);
        this.list_Title = list_Title;
        f = new Fragment[list_Title.size()];
    }
    @Override
    public Fragment getItem(int position) {
        Fragment fg = f[position];
        if (fg == null) {
            fg = new Fragment3();
            f[position] = fg;
            Bundle bundle = new Bundle();
            bundle.putString("title",list_Title.get(position));
            f[position].setArguments(bundle);
        }
        return fg;
    }

    @Override
    public int getCount() {
        return list_Title.size();
    }
    //此方法用来显示tab上的名字
    public CharSequence getPageTitle(int position) {
        return (CharSequence) list_Title.get(position % list_Title.size());
    }

}
